function [TSTART, DELT, NSTEP, FREQ, HMEAS, para, dat] = dtsrin(filex)


iy(2048) = 0;
iy2(2048) = 0;

more = true; % variable for while loop
while more
  % decide whether this is native or ESP380 file
  ext = ' ';
  dot = strfind(filex, '.');
  if isempty(dot) == false
    ext = filex(dot+1:dot+3);
  end
  ibru = 0;
  if strcmpi(ext, 'spc') == true
    ibru = 1;
  end
  if strcmpi(ext, 'dta') == true
    ibru = 2;
  end
  if ibru == 1 || ibru == 2
    % read in Bruker file
    isim = 1;
    % zero array for parameters
    para(35) = 0;
    if ibru == 1
      % read in ESP380 file
      % [para, iy, iy2, title1, title2] = tranbrpl(filex, isim);
      [para, dat] = brukerin(filex);
    else
      % read in E580 file
      % [para, iy, iy2, title1, title2] = trelpl(filex, isim);
      [para, dat] = brukerin(filex);
    end
    if isim == 9
      errordlg('Error opening file.');
      filex = uigetfile('*.*', 'Enter Experimental Data File');
      continue;
    end
    NSTEP = para(13);
    ip8 = round(para(8));
    if ip8 == 6
      errordlg('File not identified as saturation recovery or inversion recovery.');
      filex = uigetfile('*.*', 'Enter Experimental Data File');
      continue;
    end
    
    TSTART = para(20);
    if TSTART == 0
      TSTART = inputdlg('Enter value of initial time (ns): ');
    end
    DELT = para(21);
    if DELT == 0
      DELT = inputdlg('Enter value for time/pt (ns): ');
    end
    tconst = para(23);
    % convert times to seconds
    DELT = DELT*1E-9;
    TSTART = TSTART*1E-9;
    for ij = 1:NSTEP
      exper(ij) = iy(ij);
    end
    HMEAS = para(10);
    if HMEAS == 0
      HMEAS = inputdlg('Enter field at which experiment was done: ');
    end
    FREQ = para(9);
    if FREQ == 0
      FREQ = inputdlg('Enter microwave frequency: ');
    end
    more = false;
  else
    % read in native file
    fid = fopen(filex);
    A = textscan(fid, '%f %f %f %f %f',1);
    NSTEP = A{1};
    TSTART = A{2};
    DELT = A{3};
    ip8 = A{4};
    tconst = A{5};
    
    if ip8 ~= 4
      fclose(filex);
      errordlg('This is not a saturation recovery file.');
      return;
    end
    more = false;
    % convert times to seconds
    TSTART = (TSTART + tconst)*1E-9;
    DELT = DELT*1E-9;
    
    NC = ceil(NSTEP/5); % Number of columns
    exper = textscan(fid, '%f %f %f %f %f', NC);
    A = exper{1};
    B = exper{2};
    C = exper{3};
    D = exper{4};
    E = exper{5};
    exper = [A'; B'; C'; D'; E'];
    exper = exper(:);
    extraDat = NC*5-NSTEP;
    exper = exper(1:end-extraDat);
    dat = exper;
    para = textscan(fid, '%f', 35);
    if isempty(para{1})
      errordlg('This is a file without a parameter block.');
      prompt = {'Enter field for experiment:','Enter frequency for experiment:'};
      dlg_title = 'Missing Parameter Block';
      num_lines = 1;
      answer = inputdlg(prompt, dlg_title, num_lines);
      HMEAS = answer(1);
      FREQ = answer(2);
    else
      FREQ = para{1}(9);
      HMEAS = para{1}(10);
    end
    fclose(fid);
  end
end
return
end